/** 
* 文 件 名:RemoteConsultationActivity.java
* Copyright (C) 2007-2012:杭州希禾信息技术有限公司 版权所有 
* 创 建 人:Zhaowb
* 日    期:2012-4-5 下午9:14:26
* 修 改 人: 
* 日   期:
* 修改描述:
* 描   述:TODO
*/
package net.seehealth.healthpad.ui;

import java.util.ArrayList;
import java.util.List;

import net.seehealth.healthpad.R;
import net.seehealth.healthpad.application.adapter.ChatContentAdapter;
import net.seehealth.healthpad.application.adapter.OftenWordAdapter;
import net.seehealth.healthpad.application.adapter.PopOnLineAdapter;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;

/**
 * @className RemoteConsultationActivity
 * @author 赵文斌
 * @description 远程咨询
 * @date 2012-3-20 下午7:38:34
 */

public class RemoteConsultationActivity extends BaseActivity {
	/** 在线互动  **/
	private ImageView mOnlineInteractiveView;
	
	/**
	 * 在线人
	 */
	private ListView mOnline_people_listView;
	
	/**
	 * 常用语
	 */
	private ListView mOnline_word_listview;
	
	/**
	 * 聊天编辑框
	 */
	private EditText mOnline_chat_ext;
	
	/**
	 * 聊天列表
	 */
	private ListView mOnLine_messge_listview;
	
	private Button  mSend_btn;
	
	
	/**
	 * 关闭按钮
	 */
	private ImageButton mClose_btn;
	private PopOnLineAdapter mOnLineAdapter;
	private OftenWordAdapter mOftenWordAdapter;
	
	/**
	 * 聊天集合
	 */
	private  List<String> list_msg;
	/** 聊天消息适配器 **/
	private ChatContentAdapter mChatContentAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initView();
		initData();
	}

	/**
	 * 初始化视图
	 */
	private void initView(){
		setContentView(R.layout.online_interactive_pop);
		LayoutParams p = getWindow().getAttributes();  	// 获取对话框当前的参数值
	//	p.height = (int) (Constants.Screen.HEIGHT * 1.0);   	// 高度设置为屏幕的1.0
	//	p.width = (int) (Constants.Screen.WIDTH * 1.0);    // 宽度设置为屏幕的1.0
		mOnline_chat_ext = (EditText)findViewById(R.id.pop_online_chat_input);
		mOnline_people_listView = (ListView)findViewById(R.id.pop_list_view);
		mOnline_word_listview = (ListView)findViewById(R.id.pop_word_list);
		mOnLine_messge_listview = (ListView)findViewById(R.id.pop_chat_list);
		mSend_btn = (Button)findViewById(R.id.pop_send_btn);
		list_msg = new ArrayList<String>();
		mSend_btn.setOnClickListener(mClickListener);
	}
	
	/**
	 * 初始化数据
	 */
	private void initData(){
		mOnLineAdapter = new PopOnLineAdapter(mContext);
		mOnLineAdapter.setData(getPopDoctorNameList());
		mOnline_people_listView.setAdapter(mOnLineAdapter);
		
		mOftenWordAdapter = new OftenWordAdapter(mContext);
		mOftenWordAdapter.setData(getPopOftenWordList());
		mOnline_word_listview.setAdapter(mOftenWordAdapter);
		
		mChatContentAdapter = new ChatContentAdapter(this);
		mChatContentAdapter.setData(list_msg);
		mOnLine_messge_listview.setAdapter(mChatContentAdapter);
		
	}

	private List<String> getPopDoctorNameList(){
		List<String> list =  new ArrayList<String>();
		list.add("赵医生");
		list.add("刘医生");
		list.add("黄医生");
		return list;
		
	}
	
	private List<String> getPopOftenWordList(){
		List<String> list =  new ArrayList<String>();
		for(int i = 0;i<10;i++){
			list.add("你好，很高兴见到你");
		}
		return list;
		
	}
	/**
	 * 点击事件
	 */
	View.OnClickListener mClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.pop_close_btn:		// 关闭按钮
				finish();
				overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
				break;

			case R.id.pop_send_btn:
				String msgContent = mOnline_chat_ext.getText().toString().trim();
				if(msgContent.equals("")){
					showToast(R.string.not_empty, mContext);
				}else{
					list_msg.add(msgContent);
					chatRefush();
				}
				break;
			}
		}
	};
	
	/**
	 * 聊天刷新
	 */
	private void chatRefush(){
		mChatContentAdapter.setData(list_msg);
		mOnLine_messge_listview.setVisibility(View.GONE);
		mChatContentAdapter.notifyDataSetChanged();
		mOnLine_messge_listview.setVisibility(View.VISIBLE);
		mOnline_chat_ext.setText("");
	}
	
}
